/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.thread;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javaseapp - T1
 * <p>Powered by webrx On 2021-08-26 17:16:42
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class T1 {
    public static void main(String[] args) {
        //interrupte 中断
        var t = new Thread(() -> {
            Thread tt = Thread.currentThread();
            String tn = tt.getName();
            System.out.printf("%s线程启动了.%n", tn);
            while (!tt.isInterrupted()) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (Exception e) {
                    break;
                }
                System.out.println("...");
            }
            System.out.printf("%s结束了.%n", tn);
        }, "T1");
        t.start();

        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (Exception e) {
            e.printStackTrace();
        }

        synchronized (T1.class) {
            System.out.println(t.isInterrupted()); //false
            t.interrupt();//执行线程中断后
            System.out.println(t.isInterrupted());//true
        }
    }
}
